#include <iostream>
#include <string>
#include <unistd.h>
#include "blockqueue.hpp"
using namespace BlockQueue;
struct Thread
{
    Thread() {}
    Thread(blockqueue<int> &bq, std::string name) : _bq(bq), _name(name) {}
    blockqueue<int> _bq;
    std::string _name;
};
void *write(void *args)
{
    int cnt = 1;
    Thread *td = static_cast<Thread *>(args);
    while (true)
    {
        sleep(1);
        td->_bq.Write(cnt);
        std::cout << td->_name << "write : " << cnt << std::endl;
        cnt++;
    }
}
void *read(void *args)
{
    int msg = 0;
    Thread *td = static_cast<Thread *>(args);
    while (true)
    {
        // sleep(1);
        td->_bq.Read(&msg);
        std::cout << td->_name << "read : " << msg << std::endl;
    }
}

int main()
{
    pthread_t t1, t2;
    // blockqueue<int> *bq = new blockqueue<int>;
    Thread *td = new Thread;
    td->_name = "thread-1 ";
    // t1写
    pthread_create(&t1, nullptr, write, td);
    td->_name = "thread-2 ";
    // t2写
    pthread_create(&t2, nullptr, read, td);

    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    return 0;
}